<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>支付配置</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">通道标识</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-row">
                    <div class="layuiAdmin-btns" style="margin-bottom: 10px;">
                        <a lay-href="config/pay_interface_type/create" class="layui-btn" data-type="all" data-events="create">新增通道标识</a>
                        <a lay-href="config/pay_interface_type/create" class="layui-btn" data-type="all" data-events="create">批量修改通道标识</a>
                        <button class="layui-btn layui-btn-danger" id="btnDelete">删除</button>
                    </div>
                </div>
                <table class="layui-hide center" id="cList"></table>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['table','util', 'form'], function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        //标题内容模板
        var tplTitle = function(d){
            return '<a class="layui-btn layui-btn-sm" lay-href="config/pay_interface_type/update/ifTypeCode='+ d.ifTypeCode +'">编辑</a>'
        };

        var tplStatus = function(d){
            if(d.status == 0) {
                return "关闭";
            }else if(d.status == 1) {
                return "<span style='color: red'>开启</span>";
            }
        };

        table.render({
            elem: '#cList'
            ,url: layui.setter.baseUrl + '/config/pay_interface_type/list'
            ,where: { access_token: layui.data(layui.setter.tableName).access_token}
            ,id: 'tableReload'
            ,cols: [[
                {type: 'checkbox'} // 添加复选框列
                ,{field:'ifTypeCode', title: '通道标识代码'}
                ,{field:'ifTypeName',  title: '通道标识名称'}
                ,{field:'ifTypeIp',  title: '通知ip'}
                ,{field:'status', title: '状态',templet: tplStatus }
                ,{field:'edite', width: 200, title: '操作', templet: tplTitle }
            ]]
            ,page: true
            ,skin: 'line'
        });

        // 监听删除按钮点击事件
        $('#btnDelete').click(function () {
            var checkStatus = table.checkStatus('tableReload');
            var data = checkStatus.data;
            var payInterfaceTypeList = [];
            for (var i = 0; i < data.length; i++) {
                payInterfaceTypeList.push(data[i].ifTypeCode);
            }
            if (payInterfaceTypeList.length > 0) {
                // 调用删除接口，payInterfaceTypeList为要删除的通道标识数组
                $.ajax({
                    url: layui.setter.baseUrl + '/config/pay_interface_type/deleteList',
                    type: 'POST',
                    data: {payInterfaceTypeList: payInterfaceTypeList.join(',')},
                    success: function () {
                        layer.msg('删除成功');
                        // 删除成功后重新加载表格数据
                        table.reload('tableReload');
                    },
                    error: function (xhr, status, error) {
                        layer.msg('删除失败：' + error); // 显示错误信息
                    }
                });
            } else {
                layer.msg('请选择要删除的通道标识');
            }
        });

        // 渲染表单
        form.render();

    });
</script>